﻿using System.Runtime.CompilerServices;
using System.Threading;

namespace LT_Kernel
{
    /// <summary>
    /// 提供自动取消订阅机制
    /// </summary>
    public class AutoCancleToken : ILifecycle
    {
        protected CancellationTokenSource TokenSource = new CancellationTokenSource();

        public virtual void OnInit(ITuple tuple = null)
        {
        }

        public virtual void OnRemove()
        {
            using (TokenSource)
            {
                TokenSource.Cancel();
            }
        }

        public virtual void OnInitFinish()
        {
        }
    }
}